package org.com.gamemall.Controller;


import org.com.gamemall.Entity.Voucher;
import org.com.gamemall.Service.IVoucherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * <p>
 * 代金券表 前端控制器
 * </p>
 *
 * @author 277
 * @since 2025-07-23
 */
@RestController
@RequestMapping("/voucher")
public class VoucherController {
    @Autowired
    private IVoucherService voucherService;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @GetMapping("/seckill")
    public ResponseEntity<List<Voucher>> querySeckillVoucher() {
        List<Voucher> vouchers = voucherService.list();
        return ResponseEntity.ok()
                .contentType(MediaType.APPLICATION_JSON)
                .body(vouchers);
    }

    @PostMapping("/seckill/{id}")
    public String seckillVoucher(@PathVariable("id") Long id) throws InterruptedException {
     return  voucherService.seckill(id);
    }
    @PostMapping("/add")
    public ResponseEntity<Voucher> addVoucher(@RequestBody Voucher voucher) {
    return voucherService.addSeckill(voucher);
    }

}
